/*
 * Copyright (c) 2025 Li Auto Inc. and its affiliates
 * Licensed under the Apache License, Version 2.0(the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <nuttx/config.h>
#include <arch/irq.h>
#include <stddef.h>

#include "IfxSrc.h"
#include "IfxCpu.h"

#define TC3XX_UART_RECEIVE_INT_SRC   84

/****************************************************************************
 * Name: up_affinity_uart
 *
 * Description:
 *   Affinity uart receive irq to cpu.
 *
 ****************************************************************************/

void up_affinity_uart(int irq_prio, int cpu)
{
	volatile Ifx_SRC_SRCR *src =
		(Ifx_SRC_SRCR *)((unsigned int)(&SRC_CPU_CPU0_SB) + TC3XX_UART_RECEIVE_INT_SRC);

	IfxSrc_disable(src);
	IfxSrc_init(src, (cpu == 0) ? 0 : (cpu + 1), irq_prio);
	IfxSrc_enable(src);
}
